package es.xpt.ysf.commons.location.model;

import es.xpt.ysf.model.Item;

/**
 * Represents a city.
 * 
 * @author joseignacio.garces@xplayat.es
 * @version YSF 1.0
 * @since
 */
@SuppressWarnings("serial")
public class City extends Item {

	/**
	 * The code of the country to which the city belongs.
	 */
	private String countryCode;
	/**
	 * The code of the province to which the city belongs.
	 */
	private String provinceCode;


	public City() {

	}

	/**
	 * Constructor of this class with appropriate parameters. Initializes the
	 * values of instance variables with appropriate values.
	 * 
	 * @param description
	 * @param localizacion
	 * @param codigo
	 */
	public City(String code, String description) {
		super(code, description);
	}
	/**
	 * This method checks not null fields declared in YSF_CB_POBLACION table.
	 * 
	 * @return true if all not null fields have a value
	 */
	public boolean checkRequired() {
		if (getDescription() == null)
			return false;
		if (getCode() == null)
			return false;
		if (provinceCode == null)
			return false;
		return true;
	}

	public boolean checkRequiredI18n() {
		if (getDescription() == null)
			return false;
		if (getCode() == null)
			return false;
		if (getLocale() == null)
			return false;
		return true;
	}

	/**
	 * This method checks the primary keys fields.
	 * 
	 * @return true if all fields in the primary Key have a value
	 */
	public boolean checkPrimaryKey() {
		if (getCode() == null)
			return false;
		if (provinceCode == null)
			return false;
		return true;
	}

	/**
	 * This method validates the object values
	 * 
	 * @return true if everything is ok
	 */
	public boolean validateData() {
		if (getDescription().length() > 80)
			return false;
		if (getCode().length() > 50)
			return false;
		if (provinceCode != null && provinceCode.length() > 50)
			return false;
		return true;
	}

	/**
	 * Clone will return identical deep copy of this valueObject. Note, that
	 * this method is different than the clone() which is defined in
	 * java.lang.Object. Here, the retuned cloned object will also have all its
	 * attributes cloned.
	 * 
	 * @return the cloned object
	 * @throws CloneNotSupportedException 
	 */
	public Object clone() throws CloneNotSupportedException {
		City cloned = (City)super.clone();
		cloned.setCountryCode(countryCode);
		cloned.setProvinceCode(provinceCode);
		return cloned;
	}

	/**
	 * toString will return String object representing the state of this
	 * valueObject. This is useful during application development, and possibly
	 * when application is writing object states in textlog.
	 */
	public String toString() {
		StringBuffer ret = new StringBuffer();
		ret.append(this.getClass().getName() + " :\n");
		ret.append("description='" + getDescription() + "'\n");
		ret.append("country='" + countryCode + "'\n");
		ret.append("code='" + getCode() + "'\n");
		ret.append("province='" + provinceCode + "'\n");
		return ret.toString();
	}

	/**
	 * @return the countryCode
	 */
	public String getCountryCode() {
		return countryCode;
	}

	/**
	 * @param countryCode
	 *            the countryCode to set
	 */
	public void setCountryCode(String countryCode) {
		this.countryCode = countryCode;
	}

	/**
	 * @return the provinceCode
	 */
	public String getProvinceCode() {
		return provinceCode;
	}

	/**
	 * @param provinceCode
	 *            the provinceCode to set
	 */
	public void setProvinceCode(String provinceCode) {
		this.provinceCode = provinceCode;
	}
		@Override
	public int hashCode() {
		String code = getCode();
		if (code != null)
			return code.hashCode();
		return super.hashCode();
	}
}

// This file has been generated by Logic Generator v1.0
